﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FlotasDesktop;
using System.Data.SqlClient;

namespace GestorDeFlotasDesktop.AbmAuto
{
    public partial class BajaAuto : Form
    {
        String conexion;
        String idAuto;

        public BajaAuto()
        {
            InitializeComponent();
            Utils utils = new Utils();
            conexion = utils.cargarProperties();
            
            
        }

        public void mostrateConCampos(String idAuto,String licencia, String rodado, String id_marca, String modelo, String patente, String id_reloj, Boolean habilitado)
        {
            using (SqlConnection connection = new SqlConnection(conexion))
            {
                try
                {
                    using (SqlCommand command = new SqlCommand())
                    {
                        String marca;
                        this.idAuto = idAuto;
                        connection.Open();
                        command.Connection = connection;
                        command.CommandType = System.Data.CommandType.StoredProcedure;
                        command.CommandText = "TEQUILASO.sp_marca_con_id";
                        command.Parameters.AddWithValue("@id", id_marca);
                        SqlParameter countParameter = new SqlParameter("@retorno", SqlDbType.NVarChar, 255);
                        countParameter.Direction = ParameterDirection.Output;
                        command.Parameters.Add(countParameter);
                        command.ExecuteNonQuery();
                        marca = command.Parameters["@retorno"].Value.ToString();
                        
                        
                        connection.Close();

                        marcaTextBox.Text = marca;
                        licenciaTextBox.Text = licencia;
                        modeloTextBox.Text = modelo;
                        patenteTextBox.Text = patente;
                        relojTextBox.Text = id_reloj;
                        this.Show();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
           



        }
       
        private void button1_Click(object sender, EventArgs e)
        {
            using (SqlConnection connection = new SqlConnection(conexion))
            {
                try
                {
                    using (SqlCommand command = new SqlCommand())
                    {

                        connection.Open();
                        command.Connection = connection;
                        command.CommandType = System.Data.CommandType.StoredProcedure;
                        command.CommandText = "TEQUILASO.sp_bajaAutomovil";
                        command.Parameters.AddWithValue("@Id", this.idAuto);
                        command.ExecuteNonQuery();
                        connection.Close();
                        this.Close();
                        MessageBox.Show("Baja realizada con éxito");
                        
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message,"Baja automovil - error");
                }
            }
        }

        private void BajaAuto_Load(object sender, EventArgs e)
        {

        }

    }
}
